
package busserver;

import BusLib.Tile;
import java.util.ArrayList;
import java.util.List;
import org.restlet.Context;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.representation.ObjectRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.representation.Variant;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
import java.io.*;
import org.restlet.representation.FileRepresentation;

public class TileResource extends ServerResource {
    @Get()
    public FileRepresentation getData() {
        try {
               // Pentru a obtine textul id-urilor
            String idTile = (String)getRequest().getAttributes().get("ID");
            int tileId = Integer.parseInt(idTile);

            DataProvider provider = BusApplication.getProvider();
            String tilePath = provider.GetTilePath(tileId);

            String currentDir= System.getProperty("user.dir");
            String tiles="tiles";

            File file1 = new File(currentDir);
            File file2 = new File(file1,tiles);
            File file3 = new File(file2,tilePath);
            tilePath=file3.getPath().toString();
           
            return new  FileRepresentation(tilePath, MediaType.IMAGE_ALL,100);
        }
        catch(Exception e) {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return null;
        }
    }

}
